package com.itheima.springbootwebtest.controller;

import com.itheima.springbootwebtest.pojo.Result;
import com.itheima.springbootwebtest.pojo.WareHouse;
import com.itheima.springbootwebtest.pojo.WareHouseVO;
import com.itheima.springbootwebtest.service.WareHouseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * TODO
 *接口描述：
 * 销售出库时，需按仓库现存量，从多到少依次出库，直至满足出库数量要求，例如，本次需出库5250，
 * 则库存最多的先出库，即C库先出2428，剩余0 ， A库再出1827剩余0 ， B库最后出995 剩余69
 * 请结合以上库存扣减策略，实现根据出库数量，计算出所有仓库出库、结存情况功能的接口
 * 请求路径：/warehouse/out/{restock}
 * 请求示例：`/warehouse/out/5250`
 * 请求方式：get
 * 响应数据：
 * @Author mr.luo
 * @Date 13 4月 2025 16:24
 */
@RestController
@RequestMapping("/warehouse")
@Slf4j
public class WareHouseController {
    @Autowired
    private WareHouseService wareHouseService;

    /**
     * 查询仓库
     * @param
     * @return
     */
    @PostMapping("/list")
    public Result restock(@RequestBody WareHouse warehouseName) {
      List<WareHouse> list = wareHouseService.select(warehouseName);
      return Result.success(list);
    }

    @GetMapping("/out/{restock}")
    public Result getWarehouse(@PathVariable Integer restock) {
        List<WareHouseVO> list = wareHouseService.selectGetWarehouse(restock);
        return Result.success(list);
    }
}
